<?php
include_once 'library.php';
include_once 'lib_map.php';
include_once 'lib_place.php';
include_once 'lib_player.php';
  
$facebook_id = isset($_POST['fb_sig_user']) ? $_POST['fb_sig_user'] : null;

$action = $_POST['action'];
$opponent_id = $_POST['value'];

$player = getPlayerData($facebook_id);

$player->health--;

$playerData = "[ Health $player->health/$player->health_max | Stamina $player->stamina/$player->stamina_max | Strength $player->strength | Dexterity $player->dexterity | Energy $player->energy | Skill $player->skill | Coins $player->coins ]";
$fightData = "<table><tr><td>Player $action result in XHTML. Your opponent is $opponent_id. <div class='review_pic'><img src='".IMAGE_HOST_URL."/images/monsters/alien.gif' alt='Alien' /></div> </td></tr><tr><td>Player just lost 1 health point. Health = $player->health.</td></tr></table>";
//$fightData = "<p>Test fight result</p>";
//if ($player->health > 20) {
//    $fightData .= "<input type='button' onclick='do_ajax(\"ajax\",$opponent_id);return false;' value='Fight' >";
//}

$jsonData['player'] = $playerData;
$jsonData['fight'] = $fightData;

echo json_encode($jsonData);

if ($player->health <= 0) { $player->health = $player->health_max;}

updatePlayerData($player);

//echo '{"fight": "'.addslashes($fightData).',"player": "'.addslashes($playerData).'"}';

?>
